package com.eonmind.ai.converts;

import cn.hutool.json.JSONUtil;
import com.eonmind.ai.dto.AiDrawDto;
import com.eonmind.common.provider.entity.ai.AiArtwork;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import java.util.Collection;
import java.util.List;

public class AiDrawConvert {
    public static AiDrawDto.MjDrawTaskQueryResponse toMjDrawTaskQueryResponse(AiArtwork aiArtwork) {
        AiDrawDto.MjDrawTaskQueryResponse taskQueryResponse = new AiDrawDto.MjDrawTaskQueryResponse();
        BeanUtils.copyProperties(aiArtwork, taskQueryResponse);
        taskQueryResponse.setButtons(AiDrawConvert.toMjDrawTaskQueryResponseButtons(aiArtwork));
        return taskQueryResponse;
    }

    private static List<AiDrawDto.MjDrawTaskQueryResponse.Button> toMjDrawTaskQueryResponseButtons(AiArtwork aiArtwork) {
        String extraJson = aiArtwork.getExtraJson();
        if (StringUtils.isNoneBlank(extraJson) && JSONUtil.isTypeJSON(extraJson)) {
            return JSONUtil.toList(extraJson, AiDrawDto.MjDrawTaskQueryResponse.Button.class);
        }
        return List.of();
    }

    public static Collection<AiDrawDto.MjDrawTaskQueryResponse> toMjDrawTaskQueryResponseList(List<AiArtwork> contentData) {
        List<AiDrawDto.MjDrawTaskQueryResponse> list = contentData.stream()
                .map(AiDrawConvert::toMjDrawTaskQueryResponse)
                .toList();
        return list;
    }
}
